package com.lg.controller;


import com.lg.pojo.JobInfo;
import com.lg.service.JobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/lgjob")
public class JobController {

    @Autowired
    private JobService jobService;

    @PostMapping(value = "/createNewJob")
    private String createNewJob(@RequestBody JobInfo jobInfo) {
        boolean isCreated = false;
        try {
            isCreated = jobService.createNewJob(jobInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (isCreated) {
            return "Create new job successfully!";
        } else {
            return "Create new job failed!";
        }
    }

    @RequestMapping(value = "/selectJobInfoById")
    private JobInfo selectJobInfoById(@RequestParam("id") Long id) {
        return jobService.selectJobInfoById(id);
    }

    @PostMapping(value = "/updateJobInfo")
    private String updateJobInfo(@RequestBody JobInfo jobInfo) {
        boolean isUpdated = false;
        try {
            isUpdated = jobService.updateJobInfo(jobInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (isUpdated) {
            return "Update job info successfully!";
        } else {
            return "Update job info failed!";
        }
    }

    @RequestMapping(value = "/deleteJobInfo")
    private String deleteJobInfo(@RequestParam("id") Long id) {
        boolean isDeleted = false;
        try {
            isDeleted = jobService.deleteJobInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (isDeleted) {
            return "Delete job info successfully!";
        } else {
            return "Delete new job failed!";
        }
    }
}
